<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>修改密码</title>
    <link href="../../../css/main.css" rel="stylesheet" type="text/css">
    <link href="../../../layer_v2.1/layer/skin/layer.css" rel="stylesheet" type="text/css">
    <link href="../../../bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="../../../bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">
</head>

<body>
    <div class="form-con">
        <div>
            <a class="find_a">旧密码：</a>
            <input id="pwd1" maxlength="20" type="text" class="form_input text_ient" placeholder="输入旧密码" />
        </div>
        <div>
            <a class="find_a">新密码：</a>
            <input id="pwd2" maxlength="20" type="password" class="form_input text_ient" placeholder="请输入不少于6位的新密码" />
        </div>
        <div style="position: relative;right: 8px;">
            <a class="find_a">确认密码：</a>
            <input id="pwd3" maxlength="20" type="password" class="form_input text_ient" placeholder="再次输入密码" />
        </div>
        <input type="button" value="确认修改" class="but_find" id="btn" style="width: 240px;position: relative;left: 31px;"/>
    </div>
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/date/js/laydate.js"></script>
    <script src="../../../layer_v2.1/layer/layer.js"></script>
    <script src="../../../bstable/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        localStorage.setItem('name', '密码管理/修改密码')
    
        $(function () {
            $('#btn').on('click', function() {
                var pwd1 = $('#pwd1').val()
                var pwd2 = $('#pwd2').val()
                var pwd3 = $('#pwd3').val()
                var token = JSON.parse(localStorage.getItem('userInfo')).token
                console.log(token)
                if(!pwd1) {
                    return alert('请输入旧密码')
                }
                if(!pwd2) {
                    return alert('请输入新密码')
                }
                if(pwd2.length < 6) {
                    return alert('新密码长度不可小于6位')
                }
                if(!pwd3) {
                    return alert('请输入确认密码')
                }
                if(pwd2 != pwd3) {
                    return alert('两次密码输入不一致')
                }

                $.ajax({
                    url: baseUrl + "/passwd ",
                    method: "put",
                    headers: {
                        "Authorization": token
                    },
                    data: {
                        password: pwd1,
                        newPassword: pwd2
                    },
                    success: function (data) {
                        if(data.code === 200) {
                            alert('修改成功')
                        }else {
                            alert(data.message)
                        }
                    },
                    error(err) {
                        alert(JSON.parse(err.responseText).message)
                    }
                })
                console.log(11)
            })
        });

    </script>
</body>

</html>